-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor: add test + docs for 2 argument trunc with columns #7042
Conversation
@Syleechan would you have time to review this PR? |
# trunc with columns and precision | ||
query RRR rowsort | ||
select trunc(a, 3) as a3, trunc(a, 1) as a1, trunc(arrow_cast(a, 'Float64'), 3) as a3_f64 from small_floats; | ||
---- | ||
-0.7 -0.7 -0.7 | ||
-1 -1 -1 | ||
0.2 0.2 0.2 | ||
0.5 0.5 0.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, as a
has at most 1 decimal point, trunc(a, 3)
or trunc(a, 1)
basically cannot show the difference. I think it doesn't actually test what we want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add some long decimal point float number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
trunc(numeric_expression[, decimal_places]) | ||
``` | ||
|
||
#### Arguments | ||
|
||
- **numeric_expression**: Numeric expression to operate on. | ||
Can be a constant, column, or function, and any combination of arithmetic operators. | ||
|
||
- **decimal_places**: Optional. The number of decimal places to truncate to. | ||
Defaults to 0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc looks good to me. Just one question. Can decimal_places
be negative?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can not be negative, modify the trunc function just meet the self-defined precision of decimal to '.'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL turns out that negative precision means "truncate to the left of the decimal place": https://www.postgresqltutorial.com/postgresql-math-functions/postgresql-trunc/#:~:text=If%20the%20precision%20argument%20is,The%20precision%20argument%20is%20optional.
postgres=# select trunc(12345.6789, -2);
trunc
-------
12300
(1 row)
This is actually what the current datafusion implementation does too so I have added a test and updated the docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @alamb , I left some comments.
# trunc with columns and precision | ||
query RRR rowsort | ||
select trunc(a, 3) as a3, trunc(a, 1) as a1, trunc(arrow_cast(a, 'Float64'), 3) as a3_f64 from small_floats; | ||
---- | ||
-0.7 -0.7 -0.7 | ||
-1 -1 -1 | ||
0.2 0.2 0.2 | ||
0.5 0.5 0.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add some long decimal point float number
trunc(numeric_expression[, decimal_places]) | ||
``` | ||
|
||
#### Arguments | ||
|
||
- **numeric_expression**: Numeric expression to operate on. | ||
Can be a constant, column, or function, and any combination of arithmetic operators. | ||
|
||
- **decimal_places**: Optional. The number of decimal places to truncate to. | ||
Defaults to 0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can not be negative, modify the trunc function just meet the self-defined precision of decimal to '.'
Thanks @viirya and @Syleechan - I have addressed your comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Approved.
Which issue does this PR close?
Related to #6942 from @Syleechan
Rationale for this change
While reviewing #6942 I noticed the two argument version of
trunc
wasn't tested via sql and it wasn't documentedWhat changes are included in this PR?
add test + docs for 2 argument trunc with columns
Are these changes tested?
Yes
Are there any user-facing changes?